var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        language: "",
        store: "",
        store_id: "",
        commodity_data: [],
        goods_length: "",
        type: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        goods_audit: 0,
        goods_name: ""
    },
    onLoad: function(t) {
      console.log(t,'options')
      this.setData({
        store_id: t.store_id
      })
    },
    onReady: function() {
    },
    onShow: function() {
      this.initData()
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        
    },
    onShareAppMessage: function() {},
    _getJson: function() {
        var t = this, o = "", e = {};
        "store" == this.data.store ? (o = "plugin.store-cashier.frontend.store.goods.get-goods-list", 
        e = {
            store_id: this.data.store_id
        }) : "supplier" == this.data.store && (o = "plugin.supplier.frontend.goods.get-goods-list", 
        e = {
            sid: this.data.store_id
        });
        var s = a.getNetAddresss(o);
        a._postNetWork({
            url: s,
            showToastIn: !1,
            data: e,
            success: function(o) {
                var e = o.data;
                if (1 == e.result) {
                    if (t.setData({
                        commodity_data: []
                    }), "store" == t.data.store) {
                        for (var s = 0; s < e.data.goods_data.length; s++) e.data.goods_data[s].edit_active = !1;
                        console.log(e.data, "数组的合并"), t.setData({
                            goods_length: e.data.count,
                            total_page: e.data.goods_data.last_page,
                            commodity_data: e.data.goods_data.data
                        }), "https://dev3.yunzshop.com/" == a.data.host && t.setData({
                            commodity_data: e.data.goods_data
                        });
                    } else if ("supplier" == t.data.store) {
                        for (var d = 0; d < e.data.list.length; d++) e.data.list[d].edit_active = !1;
                        console.log(e.data, "数组的格式"), t.setData({
                            total_page: e.data.list.last_page,
                            goods_length: e.data.list.data.length,
                            commodity_data: e.data.list.data
                        });
                    }
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    moreEvent: function(a) {
        var o = a.currentTarget.dataset.index;
        0 == this.data.commodity_data[o].edit_active ? (this.emptyEditActive(), this.setData(t({}, "commodity_data[" + o + "].edit_active", !0))) : this.emptyEditActive();
    },
    emptyEditActive: function() {
        for (var a = 0; a < this.data.commodity_data.length; a++) this.setData(t({}, "commodity_data[" + a + "].edit_active", !1));
    },
    routeTake: function() {
      console.log(this.data.store_id,'this.data.store_id')
      wx.navigateTo({
        url: "/packageC/o2o/AddFreightTemplate/AddFreightTemplate?store_id=" + this.data.store_id
    })
    },
    commodityDelete: function(t) {
        var o = this, e = t.currentTarget.dataset.index;
        wx.showModal({
            title: "提示",
            content: "此操作将永久删除该模板, 是否继续?",
            success: function(t) {
                if (t.confirm) {
                    var s = "", d = {};
                    s = a.getNetAddresss("HuanNiu.del_ps_muban")
                     a._postNetWork({
                        url: s,
                        showToastIn: !1,
                        data: {
                          id: o.data.commodity_data[e].list.id
                        },
                        success: function(t) {
                            var a = t.data;
                            if (1 == a.result) {
                                wx.showToast({
                                    icon: "none",
                                    title: "模板删除成功",
                                    duration: 1500
                                });
                                o.initData()
                            } else wx.showToast({
                                icon: "none",
                                title: a.msg,
                                duration: 1500
                            });
                        },
                        fail: function(t) {}
                    });
                } else t.cancel && wx.showToast({
                    icon: "none",
                    title: "已取消删除",
                    duration: 1500
                });
            }
        });
    },
    editJumpEvent: function(t) {
        var a = t.currentTarget.dataset.index;
        console.log(this.data.commodity_data[a].id, a, "11111222"), wx.navigateTo({
            url: "/packageC/o2o/AddFreightTemplate/AddFreightTemplate?store_id=" + this.data.store_id + "&template_id=" + this.data.commodity_data[a].list.id
        });
    },
    initData: function() {
      var i = this, n = a.getNetAddresss("HuanNiu.list_ps_muban");
            a._getNetWork({
                url: n,
                data: {
                    store_id: i.data.store_id,
                },
                success: function(a) {
                  console.log(a,'initdataaaa')
                  if(1 == a.data.result) {
                    i.setData({
                      commodity_data: a.data.data
                    })
                  }
                    
                },
                fail: function(t) {
                    console.log(t);
                }
            });
    }
});